﻿/// <reference path="../scripts/jquery-1.11.2.min.js" />
/// <reference path="../scripts/bootstrap.min.js" />

if (typeof ($) != "undefined" && $) {
    //验证用户
    CheckUser();
    $(document).ready(onReady);

}

function onReady() {
    var ua = navigator.userAgent.toLowerCase();
    var isIos = (ua.indexOf('iphone') != -1) || (ua.indexOf('ipad') != -1);

    $.ajax({
        type: "get",
        url: "api/member.ashx?ac=account&k=" + Math.random(),
        success: function (data) {
            if (data != null && data != '') {
                var m = eval("(" + data + ")");
                $("#money").html(toDecimal2(m.account));
                $("#rebate").html(toDecimal2(m.rebate));
            }
        }
    });

    $.ajax({
        type: "get",
        url: "api/member.ashx?ac=cpcount&k=" + Math.random(),
        beforeSend: function () {
            $('#loadingToast').show();
        },
        error: function () {
            showToast("数据加载失败");
        },
        success: function (data) {
            if (data != null && data != '') {
                var m = eval("(" + data + ")");
                $("#cpcount").html(m.cpcount);
                $("#wcount").html(m.wcount);
            }
        },
        complete: function () {
            $('#loadingToast').hide();
        }
    });

    $.ajax({
        type: "get",
        url: "api/common.ashx?ac=cpscheme&k=" + Math.random(),
        success: function (data) {
            var list = eval("(" + data + ")");
            var count = list.length;
            count = (count > 3) ? 3 : count;
            for (var i = 0; i < count; i++) {
                var o = list[i];
                var htm = '<div class="wcp">';
                htm += '<p>￥' + o.PrePrice + ' <span class="fline">￥' + o.OldPrice + '</span></p>';
                htm += '<p>洗车券×' + o.Quantity + '</p>';
                htm += '</div>';

                $("#wcplist").append(htm);
            }
        }
    });

    $("#divaccount").click(function () {
        window.location.href = 'account.html';
    });
    $("#divcoupons").click(function () {
        window.location.href = 'coupons.html?ct=0';
    });
    $("#divwash").click(function () {
        window.location.href = 'coupons.html?ct=1';
    });
    $("#wcplist").click(function () {
        window.location.href = 'cpbuy.html';
    });
    $("#btnbuy").click(function () {
        window.location.href = 'cpbuy.html';
    });
}

